package com.dongdongshop.service.impl;

import com.dongdongshop.data.Page;
import com.dongdongshop.mapper.TbContentCategoryMapper;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.service.ContentCategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class ContentCategoryServiceImpl implements ContentCategoryService {
    @Autowired
    private TbContentCategoryMapper tbContentCategoryMapper;

    @Override
    public Page<TbContentCategory> findList(Integer pageNum, Integer pageSize, TbContentCategory tbContentCategory) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbContentCategory> list = tbContentCategoryMapper.selectByName(tbContentCategory);
        PageInfo<TbContentCategory> pageInfo = new PageInfo<>(list);
        Page<TbContentCategory> page = new Page<>(pageInfo.getPageNum(),pageInfo.getSize(),pageInfo.getPages(),pageInfo.getList());
        return page;
    }

    @Override
    public void addInfo(TbContentCategory tbContentCategory) {
        tbContentCategoryMapper.insertSelective(tbContentCategory);
    }

    @Override
    public TbContentCategory selectById(TbContentCategory tbContentCategory) {
        Long id = tbContentCategory.getId();
        return tbContentCategoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public void UpdateInfo(TbContentCategory tbContentCategory) {
        tbContentCategoryMapper.updateByPrimaryKeySelective(tbContentCategory);
    }

    @Override
    public void deleteInfo(Long[] id) {
        tbContentCategoryMapper.deleteByid(id);
    }

    @Override
    public List<TbContentCategory> select() {
        return tbContentCategoryMapper.selectByExample(null);
    }
}
